package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbSizeParam;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbMatchParamDao {
    @Results(id = "pcbMatchParamResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcb_match_param_name", property = "pcbMatchParamName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_match_param_key", property = "pcbMatchParamKey", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_match_param_type", property = "pcbMatchParamType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_match_param_rule_type", property = "pcbMatchParamRuleType", jdbcType = JdbcType.INTEGER),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "param_options", property = "paramOptions", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })
    /*
     * 查询单个
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_PARAM +
            "<where> " +
            "<if test='id != null'>" +
            " and id = #{id}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    PcbSizeParam getById(@Param("id") Integer id);

    /*
     * 查询单个
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_PARAM +
            "<where> " +
            "<if test='paramKey != null'>" +
            " and pcb_match_param_key = #{paramKey}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbMatchParamResultMap")
    PcbSizeParam getByParamKey(@Param("paramKey") String paramKey);

    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_PARAM +
            "<where> " +
            "<if test='paramName != null'>" +
            " and pcb_match_param_name = #{paramName}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbMatchParamResultMap")
    PcbSizeParam getByParamName(@Param("paramName") String paramName);

    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATCH_PARAM +
            "<where> " +
            "<if test='id != null'>" +
            " and id = #{id}" +
            "</if>" +
            "<if test='status != null'>" +
            " and status = #{status}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbMatchParamResultMap")
    List<PcbSizeParam> getByLimit(PcbSizeParam pcbSizeParam);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_MATCH_PARAM + " (pcb_match_param_name, pcb_match_param_key, pcb_match_param_type, pcb_match_param_rule_type, param_options, remark, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{pcbMatchParamName}, #{pcbMatchParamKey}, #{pcbMatchParamType}, #{pcbMatchParamRuleType}, #{paramOptions}, #{remark}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insert(PcbSizeParam param);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_MATCH_PARAM + " where id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_MATCH_PARAM +
            "<set>" +
            "<if test='pcbMatchParamName != null and pcbMatchParamName != \"\" '>" +
            "   pcb_match_param_name  = #{pcbMatchParamName}," +
            "</if>" +
            "<if test='pcbMatchParamKey != null and pcbMatchParamKey != \"\" '>" +
            "   pcb_match_param_key  = #{pcbMatchParamKey}," +
            "</if>" +
            "<if test='pcbMatchParamType != null and pcbMatchParamType != \"\" '>" +
            "   pcb_match_param_type  = #{pcbMatchParamType}," +
            "</if>" +
            "<if test='pcbMatchParamRuleType != null '>" +
            "   pcb_match_param_rule_type  = #{pcbMatchParamRuleType}," +
            "</if>" +
            "<if test='remark != null and remark != \"\" '>" +
            "   remark  = #{remark}," +
            "</if>" +
            "<if test='paramOptions != null and paramOptions != \"\" '>" +
            "   param_options  = #{paramOptions}," +
            "</if>" +
            "<if test='sort != null'>" +
            "    sort = #{sort}," +
            "</if>" +
            "<if test='status != null'>" +
            "    status = #{status}," +
            "</if>" +
            "<if test='createTime != null'>" +
            "    create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            "    update_time = #{updateTime}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "    create_user = #{createUser}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "    update_user = #{updateUser}," +
            "</if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    Integer update(PcbSizeParam param);
}
